﻿using BizUnit;
using System.Diagnostics;
using BTS.Testing.TraceMonitor.BizUnitSteps.TraceControlAgent;

namespace BTS.Testing.TraceMonitor.BizUnitSteps
{
    /// <summary>
    /// Stops the realtime event trace
    /// </summary>
    public class StopRealtimeEventTrace : BizUnit.BizUnitOM.ITestStepOM
    {
        public const string TraceMonitorProcessName = "BTS.Testing.TraceMonitor";
        /// <summary>
        /// Executes the bizunit step
        /// </summary>
        /// <param name="testConfig"></param>
        /// <param name="context"></param>
        public void Execute(System.Xml.XmlNode testConfig, Context context)
        {
            Execute(context);
        }

        public void Execute(Context context)
        {
            Execute();
        }

        public void Execute()
        {
            var serviceAgent = new TraceControlServiceClient();
            serviceAgent.Stop();

            var processes = Process.GetProcessesByName(TraceMonitorProcessName);
            foreach (var process in processes)
            {
                process.Kill();
            }
        }

        public void Validate(Context context)
        {
            
        }
    }
}
